# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        博智科技  
# Name:         demo8024
# Description:  类的继承
# Author:       yzl
# Date:         2019-03-16
#-------------------------------------------------------------------------------

class Animal:
    def __init__(self):
        self.name = 'Animal'
        print('Animal 类')

    def eat(self):
        print('我要吃东西')


class Dog(Animal):
    def __init__(self):
        # super().__init__()
        super(Dog,self).__init__()
        print(self.name + 'dog')
        print('Dog 类')

    def walk(self):
        print('我会散步')

    def eat(self):
        # super().eat() # 调用父类的方法
        super(Dog,self).eat()
        print('狗爱吃骨头')

class Man:
    def helo(self):
        return 'helo helo'

def hello():
    return 'Hello'

if __name__ == '__main__':
    m = Man()
    m.name = 'aaa'
    print(hasattr(m, 'name'))

    print('------------------')
    age = getattr(m, 'age', 40)
    print(age)

    print('------------------')
    # 检测对象是否有 helo 这个函数,如果没有就返回,hello
    helo1 = getattr(m, 'helo', hello)
    print(helo1())

    print('------------------')
    # 给对象直接加上属性
    # setattr(m,'height',170)
    # 与上句意思相同
    m.height = 170
    print(m.height)

    setattr(m,'name','bbb')
    print(m.name)

    # animal = Animal()
    # animal.eat()
    #
    # print('------------------')
    # dog = Dog()
    # dog.eat()
    # dog.walk()
    #
    # print('------------------')
    # # 检测子类的方法
    # print(issubclass(Dog,Animal))
    #
    # print('------------------')
    # print(issubclass(Man,Animal))




